//app.js
const api = require('./utils/api');
const constant = require('./utils/constant');
const storage = require('./utils/storage')
App({
  onLaunch: function () {
    let that = this;
    // 设置头部高度
    this.setHeaderHeight();
    // 获取底部菜单栏高度
    this.setTabbarHeight();
    // 展示本地存储能力
    // var logs = wx.getStorageSync('logs') || []
    // logs.unshift(Date.now())
    // wx.setStorageSync('logs', logs)
    // api.getUserInfo();
    // 登录
    // wx.clearStorage();
    // 机型
    let _self = this;
    wx.getSystemInfo({
      success: res => {
      let modelmes = res.model;
      wx.setStorageSync('modelmes', modelmes)
      }
    })
    storage.setLoginStatus(constant.WECHATLOGIN);
    api.login().then(res => {
      // console.log('登录信息',res);
    });
  },
  globalData: {
    userInfo: null,
    // 获取状态栏高度
    statusBarHeight:wx.getSystemInfoSync().statusBarHeight,
    // 获取导航栏的高度
    jiaonang: {
      height: 0,
      top: 0,
      right: 0,
    },
    // 头部高度
    navigationHeight: 0,
    // 底部菜单高度
    tabbarHeight: 0,
    // 手机号码状态
    phoneNumber: null
  },
  // 设置头部高度
  setHeaderHeight(){
    // 获取系统信息
    const systemInfo = wx.getSystemInfoSync();
    // 获取胶囊信息
    const jiaonang = wx.getMenuButtonBoundingClientRect();
    this.globalData.statusBarHeight = systemInfo.statusBarHeight;
    this.globalData.jiaonang.height = jiaonang.height;
    this.globalData.jiaonang.top = jiaonang.top;
    this.globalData.jiaonang.right = systemInfo.screenWidth - jiaonang.right;
    this.globalData.navigationHeight = (jiaonang.top - systemInfo.statusBarHeight) * 2 + jiaonang.height + systemInfo.statusBarHeight+5;
  },
  setTabbarHeight(){
    // 获取系统信息
    const systemInfo = wx.getSystemInfoSync();
    this.globalData.tabbarHeight = ( systemInfo.screenHeight - systemInfo.windowHeight - systemInfo.statusBarHeight ) * systemInfo.pixelRatio
  }

})